function [var1,var2,difvar,difc]=checkmodels_lmj(funcmod1,funcmod2,fullp1,solveopt,addsol,varargin)
% =========================================================================
% function [var1,var2,difvar,difc]...
% checkmodels_lmj(funcmod1,funcmod2,fullp1,solveopt,addsol,varargin)
% CHECKMODELS.m 
% Use to compare the implied variance of two models 
% E.g. debugging estimations vs. observation codes 
% 
% Input
% -----
% Pass function handle for two models 
% and either 1) fullp1 which will be used for both models or 
%            2) fullp1 + fullp2 which will be used for the first and second
%            model respectively 
% Solve each model and compute the variance of the observables and see how 
% different they are. 
% 
% Output: 
% VAR1:   Variance first model 
% VAR2:   Variance 2nd   model 
% DIFVAR  Differences in variances 
% DIFC    Differences in constant for observation equation 
% 
% Alejandro Justiniano Feb 10 2009
%
% ------------------------------------------------------------------------
% MODIFIED from checkmodels
% Can now pass in solveopt and addsol.  
% -TM
% 
% =========================================================================
if nargin <5; error('Need Handle1,Handle2 and FULLP'); end 
if nargin == 5; flag_difcoef=0; disp('Single FULLP'); end; 
if nargin == 6; flag_difcoef=1; disp('Two FULLP'); end; 
[GG1,RR1,CC1,eu,SDX1,ZZ1]=feval(funcmod1,fullp1,solveopt,addsol);    
varst1=disclyap_fast(GG1(:,:,1),RR1(:,:,1)*(SDX1(:,:,1)'*SDX1(:,:,1))*(RR1(:,:,1)')); 
var1=ZZ1(:,:,1)*(varst1)*(ZZ1(:,:,1)'); 
if flag_difcoef==0
    [GG2,RR2,CC2,eu,SDX2,ZZ2]=feval(funcmod2,fullp1,solveopt,addsol);
else
    [GG2,RR2,CC2,eu,SDX2,ZZ2]=feval(funcmod2,varargin{1},solveopt,addsol);
end 
varst2=disclyap_fast(GG2(:,:,1),RR2(:,:,1)*(SDX2(:,:,1)'*SDX2(:,:,1))*(RR2(:,:,1)')); 
var2=ZZ2(:,:,1)*varst2*(ZZ2(:,:,1)'); 
difvar=comparemat(var1,var2);     
difc  =max(abs( ZZ1(:,:,1)*CC1(:,1) - ZZ2(:,:,1)*CC2(:,1) )); 
if difc > 0.001; error('Differences in constants'); end; 